package com.qf.qfssm.web.master.filter;

import com.qf.qfssm.web.master.entity.Customer;
import com.qf.qfssm.web.master.utils.Constant;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author 刘欣
 * @createTime 2023/1/13 14:29
 * @description
 */
@WebFilter("/deregistration")
public class CustomerFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) servletRequest;
        HttpServletResponse resp = (HttpServletResponse) servletResponse;
        HttpSession session = req.getSession();
        Customer customer = (Customer) session.getAttribute(Constant.CUSTOMER_SESSION_KEY);
        if (customer != null) {
            String name = customer.getName();
            String password = customer.getPassword();

        }

        Cookie[] cookies = req.getCookies();
        if (cookies != null) {
            for (Cookie cookie : cookies) {
                String cookieValue = cookie.getValue();
                String[] split = cookieValue.split("-");
                String cookieName = split[0];
                String cookiePassword = split[1];

            }

        }

    }

    @Override
    public void destroy() {

    }
}
